package com.cbg.label.controller;

import com.cbg.label.dto.LabelInfoDTO;
import com.cbg.label.dto.LabelListDTO;
import com.cbg.label.service.IZfwLabelService;
import com.cbg.label.vo.LabelEditVO;
import com.cbg.label.vo.LabelInfoVO;
import com.cbg.label.vo.LabelQueryVO;
import com.cbg.vo.DelVO;
import com.cbg.vo.StatusVO;
import com.shuyuwl.core.support.ServerResponse;
import com.shuyuwl.core.utils.PageUtil;
import com.shuyuwl.core.vo.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 标签库管理Controller
 *
 * @author wangjuzheng
 * @since 2018-05-31
 */
@RestController
@Api(tags = "全景通查-标签库管理")
@RequestMapping("/api/label")
@CrossOrigin(allowCredentials = "true", maxAge = 3600, allowedHeaders = "*", origins = "*")
public class LabelController {

    @Resource
    private IZfwLabelService zfwLabelService;

    /**
     * 获取标签信息
     *
     * @param labelQueryVO 标签查询模型
     * @param pageVO       分页参数
     * @return 标签分页模型
     */
    @GetMapping(value = "/list")
    @ApiOperation(value = "获取标签信息")
    public ServerResponse<Page<LabelListDTO>> getLabels(LabelQueryVO labelQueryVO, @Validated PageVO pageVO) {

        PageUtil.setPageAndSize(pageVO);
        //获取标签分页信息
        Page<LabelListDTO> page = zfwLabelService.getLabels(labelQueryVO, pageVO);
        return ServerResponse.createBySuccess(page);
    }

    /**
     * 获取标签详情
     *
     * @param id 标签id
     * @return 模型
     */
    @GetMapping(value = "/detail/{id}")
    @ApiOperation(value = "获取标签详情")
    public ServerResponse<LabelInfoDTO> getLabel(@ApiParam(value = "id") @PathVariable Long id) {

        //获取标签详情
        LabelInfoDTO labelInfoDTO = zfwLabelService.getLabel(id);
        return ServerResponse.createBySuccess(labelInfoDTO);
    }

    /**
     * 标签的添加
     *
     * @param labelInfoVO 添加标签数据模型
     * @return 模型
     */
    @PostMapping
    @ApiOperation(value = "标签的添加")
    public ServerResponse addLabel(@Validated @RequestBody LabelInfoVO labelInfoVO) {

        //标签的添加
        zfwLabelService.addLabel(labelInfoVO);
        return ServerResponse.createBySuccessMessage("添加成功");
    }

    /**
     * 标签的更新
     *
     * @param labelEditVO 更新标签数据模型
     * @return 模型
     */
    @PutMapping
    @ApiOperation(value = "标签的更新")
    public ServerResponse updateLabel(@Validated @RequestBody LabelEditVO labelEditVO) {

        //标签的更新
        zfwLabelService.updateLabel(labelEditVO);
        return ServerResponse.createBySuccessMessage("更新成功");
    }

    /**
     * 修改标签状态
     *
     * @param statusVO 修改状态模型
     * @return 模型
     */
    @PutMapping(value = "/status")
    @ApiOperation(value = "修改标签状态")
    public ServerResponse updateStatus(@Validated @RequestBody StatusVO statusVO) {

        //修改标签状态
        zfwLabelService.updateStatus(statusVO.getIds(), statusVO.getStatus());
        return ServerResponse.createBySuccessMessage("修改状态成功");
    }

    /**
     * 标签的删除
     *
     * @param delVO 删除参数模型
     * @return 模型
     */
    @DeleteMapping
    @ApiOperation(value = "删除标签信息")
    public ServerResponse deleteLabel(@Validated @RequestBody DelVO delVO) {

        //标签的删除
        zfwLabelService.deleteLabel(delVO.getIds());
        return ServerResponse.createBySuccessMessage("删除标签成功");
    }
}